<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// 
//  admin_fetch_activity
//  www.6block.com
//  
//  Created by Will_Lee on 2011-06-02.
//  Copyright 2011 lishuzu. All rights reserved.
// 


class Admin_fetch_activity extends CI_Controller {

	 function __construct()
	 {
		parent::__construct();
		
		//加载来源
		$this->fromsource = $this->config->item('fromsource');
 		$this->load->model('common/security_model');
 		$this->load->model('admin/fetch_activity_model');
		if($this->security_model->isAdminLogin() === FALSE){
          showmessage('请登录', 'admin/login/index', 3);
		}

		
	 }

	function index($fromid)
	{
		$website = $this->fromsource[$fromid];
		if (!$website) {
			showmessage('未选择抓取数据源');
		}

		$data = $this->fetch_activity_model->get_activitys_data($fromid);
		$data['website'] = $website;
		$this->load->template('admin/fetch_activity_tpl', $data);
	}
	//数据抓取商品列表
	function goods($fromid, $aid){
		$website = $this->fromsource[$fromid];
		if (!$website) {
			showmessage('未选择抓取数据源');
		}
				
		$aid = $aid ? intval($aid) : '';
		if (!$aid) {
			showmessage('非法来源');
		}
		$data['activity'] = $this->fetch_activity_model->get_activity_by_aid($fromid, $aid);
		$data['goods'] = $this->fetch_activity_model->get_goods_data($fromid, $aid);
		
		$data['aid'] = $aid;
		$data['website'] = $website;
		$this->load->template('admin/fetch_goods_tpl', $data);		
	}
	
	//上架单个活动
    function uponindex($fromid, $aid)
    {
		$website = $this->fromsource[$fromid];
		if (!$website) {
			showmessage('未选择抓取数据源');
		}
		
		if (empty($aid)) {
			showmessage('没有选择任何活动');
		}
		
		$ids = array($aid);
		if (empty($ids)) {
			showmessage('没有选择任何活动');
		}
		$result = $this->fetch_activity_model->uponindexs($fromid, $ids);
		if ($result) {
			showmessage('操作成功','admin/admin_fetch_activity/index/'.$fromid, 3);	
		}else{
			showmessage('操作失败','admin/admin_fetch_activity/index/'.$fromid, 3);
		}
    }

	//批量上架活动
	function uponindexs($fromid)
	{	
		$website = $this->fromsource[$fromid];
		if (!$website) {
			showmessage('未选择抓取数据源');
		}
		
		$ids = $this->input->post('ids');
		if (empty($ids)) {
			showmessage('没有选择任何活动');
		}

		
		$result = $this->fetch_activity_model->uponindexs($fromid, $ids);
		if ($result) {
			showmessage('操作成功','admin/admin_fetch_activity/index/'.$fromid, 3);	
		}else{
			showmessage('操作失败','admin/admin_fetch_activity/index/'.$fromid, 3);
		}
	}
}
?>